<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
    <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
    <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script>
    <script type="text/javascript">
        SyntaxHighlighter.defaults['toolbar'] = false;
        SyntaxHighlighter.all();
    </script>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>Zero Configuration</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="guides.html">Guides</a>&nbsp;&gt;&nbsp;<a href="core-developers-guide.html">Core Developers Guide</a>&nbsp;&gt;&nbsp;<a href="zero-configuration.html">Zero Configuration</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">Zero Configuration</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=29352">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=29352">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=29352">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=29352">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=29352">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=29352">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent"><div class="confluence-information-macro confluence-information-macro-warning"><p class="title">Deprecated Plugin</p><span class="aui-icon aui-icon-small aui-iconfont-error confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
<p>Since 2.1 this plugin has been deprecated in favor of the <a shape="rect" href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=73711">Convention Plugin</a></p></div></div>

<p>A "Zero Configuration" Struts application or plugin uses no additional XML or properties files. Metadata is expressed through convention and annotation.  </p>

<p>As this is a new feature, and still being field-tested, the documentation is sketchy. But, here's what we have so far:</p>


<h3 id="ZeroConfiguration-FindingActions">Finding Actions</h3>

<p>Set the "actionPackages" filter init param to a comma-separated list of packages containing Action classes in web.xml. The packages and their subpackages will be scanned. All classes in the designated packages that implement Action or end in "Action" are examined.  The latter is to allow for POJO Actions that don't implement the Action interface.</p>

<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Annotation Initialization actionPackages Filter Parameter in web.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
&lt;filter&gt;
  &lt;filter-name&gt;struts2&lt;/filter-name&gt;
  &lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt;
  &lt;init-param&gt;
    &lt;param-name&gt;actionPackages&lt;/param-name&gt;
    &lt;param-value&gt;com.foo.bar,com.baz.quux&lt;/param-value&gt;
  &lt;/init-param&gt;
&lt;/filter&gt;
</pre>
</div></div>

<p>We should probably add an action annotation, so that POJOs can itall with annotations.</p>

<h3 id="ZeroConfiguration-Examples">Examples</h3>

<p>The only example right now is in the showcase, where the person package uses the classpath scanning configuration. </p>


<h3 id="ZeroConfiguration-ActionandPackagename">Action and Package name</h3>

<p>The subpackage name makes the namespace, and the action class name makes the action name.  If there is an "Action" suffix, it is dropped before creating the action name. Therefore, if the configured package is <em>com.myapp.actions</em> and the Action is <em>com.myapp.actions.</em><strong>member</strong>.EditAction, you can access it via <a shape="rect" class="external-link" href="http://server/myapp/member/edit.action" rel="nofollow">http://server/myapp/member/edit.action</a>.  For multi-word actions, the first letter is lower-cased and the rest is left alone, so the Action <code>MyCustomAction</code> will map to <code>myCustom.action</code>.</p>


<h3 id="ZeroConfiguration-Results">Results</h3>

<p><a shape="rect" href="result-annotation.html">Results</a> are defined with the Result and Results annotations at the <strong>class level</strong>. </p>


<h3 id="ZeroConfiguration-Namespaces">Namespaces</h3>
<p>The <a shape="rect" href="namespace-annotation.html">Namespace Annotation</a> overrides the namespace.</p>


<h3 id="ZeroConfiguration-ParentPackage">Parent Package</h3>

<p>The <a shape="rect" href="parentpackage-annotation.html">ParentPackage Annotation</a> configures the XWork package (an XWork package is created per Java package) to extend one or more defined packages. The best place for this annotation is on the package via the <code>package-info.java</code> file, however, for backward-compatibility, they can be specified on one or more Actions in the package.  To determine which parent packages should be set, first, it looks for the package annotation, then adds the action annotations as they are loaded.  Because the load order of Actions is undetermined, it is highly recommended you avoid putting the @ParentPackage annotation on Action classes themselves.</p>

<p>For example, if you wanted to set the parent package for the <code>com.mycompany.myapp.actions</code> package, create this package-info.java file:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
@ParentPackage("my-parent-package")
package com.mycompany.myapp.actions

import org.apache.struts2.config.ParentPackage;
</pre>
</div></div>

<p>To define multiple parent packages, list an array of package names:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
@ParentPackage({"my-parent-package1, my-parent-package2"})
package com.mycompany.myapp.actions

import org.apache.struts2.config.ParentPackage;
</pre>
</div></div>


<h3 id="ZeroConfiguration-Feedback">Feedback</h3>

<p>Stay tuned to this page for additional details and documentation. If you have a chance to  try the zero configuration feature, please share any experiences on dev@ and here.</p>

<h3 id="ZeroConfiguration-Seealso">See also </h3>
<ul><li><a shape="rect" href="zero-configuration-scanning.html">Zero Configuration Scanning</a> Use Case</li><li><a shape="rect" href="codebehind-plugin.html">Codebehind Plugin</a></li><li><a shape="rect" href="restfulactionmapper.html">RESTfulActionMapper</a></li></ul>


<h2 id="ZeroConfiguration-Next:">Next: <a shape="rect" href="annotations.html">Annotations</a></h2></div>
        </div>

        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
